C++ 基础(六)C++ 字符的输入输出、字符串的输入输出。 | 您所在的位置:网站首页 › c 输入输出字符 › C++ 基础(六)C++ 字符的输入输出、字符串的输入输出。 |
一、简介
本博客主要说明c++字符的输入输出、字符串的输入输出 参考:https://blog.csdn.net/denao/article/details/74531841 二、字符的输入输出方法1 ——getchar()和putchar() int main() { char a; char b; char c; //单字符的输入输出 a = getchar(); putchar(a); //scanf("%c", &b); //printf("%c", b); return 0; }方法2——scanf()和printf() #include "stdafx.h" //#include //#include using namespace std; int main() { char a; char b; char c; //单字符的输入输出 /*a = getchar(); putchar(a);*/ scanf("%c", &b); printf("%c", b); return 0; }该方法中,会报错: 'scanf': This function or variable may be unsafe 原因: https://www.cnblogs.com/gb2013/archive/2013/03/05/SecurityEnhancementsInTheCRT.html 方法3——cin与cout,必须应用头文件#include #include "stdafx.h" //#include #include using namespace std; int main() { char a; char b; char c; //单字符的输入输出 /*a = getchar(); putchar(a);*/ /*scanf("%c", &b); printf("%c", b);*/ cin >> a; cout > a; //cout > a; cout > a; cout |
CopyRight 2018-2019 实验室设备网 版权所有 |